//
//  JYUserAccountViewModel.swift
//  WeiBoDemo
//
//  Created by 万佳阳 on 16/8/3.
//  Copyright © 2016年 JYWan. All rights reserved.
//

import UIKit

class JYUserAccountViewModel {
    // MARK:- 将类设置成单例
    static let shareInstance : JYUserAccountViewModel = JYUserAccountViewModel()
    
    //定义属性
    var userAccount : JYUserAccount?
    
    
    // MARK:- 计算属性
    var accountpath : String {
        let accountpath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first!
        return (accountpath as NSString).stringByAppendingPathComponent("account.plist")
    }
    
    var isLogin : Bool {
        guard let userAccount = userAccount else {
            return false
        }
        guard let expiresDate = userAccount.expires_date else {
            return false
        }
        
        return expiresDate.compare(NSDate()) == NSComparisonResult.OrderedDescending
    }
    
    
    // MARK:- 重写init()函数
    init() {
        //读取归档信息
        userAccount = NSKeyedUnarchiver.unarchiveObjectWithFile(accountpath) as? JYUserAccount
    }
}
